package com.note.resources;

import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriInfo;


import com.note.pojo.User;
import com.note.service.UserService;
import com.sun.jersey.api.spring.Autowire;
import com.sun.jersey.spi.resource.Singleton;
/**
 * 用户资源类
 * 
 * @author Jack Dou
 * @since 1.0
 */
@Path("user/{id}")
@Singleton
@Autowire
public class UserResource {
	private UserService userService;
	@Context private UriInfo uriInfo;
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	/**
	 * 返回jaxb序列化为json示例
	 * 
	 * @param customerId
	 * @return
	 * @throws Exception
	 */
	@GET
	@Path("zhangsan")
	@Produces("application/json")
	public User getZhangsan() {
		User user = userService.getZhangsan();
		return user;
	}
	/**
	 * 返回jaxb序列化为json示例
	 * 
	 * @param customerId
	 * @return
	 * @throws Exception
	 */
	@GET
	@Path("lisi")
	@Produces({"application/json"})
	public User getLisi() {
		User user = userService.getLisi();
		return user;
	}
	/**
	 * 返回jaxb序列化为json集合示例
	 * 
	 * @param customerId
	 * @return
	 * @throws Exception
	 */
	@GET
	@Path("all")
	@Produces({"application/json"})
	public List<User> getUsers() {
		System.out.println(getId());
		List<User> users = userService.getUsers();
		return users;
	}
	/**
	 * 获取id
	 * @return
	 */
	public String getId() {
		MultivaluedMap<String, String> params = uriInfo.getPathParameters();
		String id = params.getFirst("id");
		return id;
	}
}